const computedTime = (exam)=>{
  return exam.map((item)=>{
    const todayDate = new Date().getTime()
    const examDate = new Date(item.time).getTime()
    const deadLine = ( examDate - todayDate ) / 1000 / 60 / 60 / 24

    item.deadLine = deadLine > 0 ? Math.floor(deadLine) : -1
    return item
  })
}

const sortTime = (exam) => {
  const time = computedTime(exam)
  let passed = time.filter(item => item.deadLine === -1)
  let coming = time.filter(item => item.deadLine !== -1).reverse()
  return Array(...coming, ...passed)
}

module.exports = {
  sortTime
}